package carltechnology.com.mahjonggame.views.impl;

import android.app.Fragment;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import butterknife.ButterKnife;
import butterknife.InjectView;
import carltechnology.com.mahjonggame.R;
import carltechnology.com.mahjonggame.presenter.IMajhongGamePresenter;
import carltechnology.com.mahjonggame.presenter.impl.MajhongGamePresenter;
import carltechnology.com.mahjonggame.views.IMahjongGameView;

/**
 * Created by WZTCM on 2016/6/6.
 */
public class MahjongGameFragment extends Fragment implements IMahjongGameView  {
    private IMajhongGamePresenter iMajhongGamePresenter;
    @InjectView(R.id.mahjonggame_content_recyleview)
    RecyclerView recyclerView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        iMajhongGamePresenter = null;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        //return super.onCreateView(inflater, container, savedInstanceState);
        View view = inflater.inflate(R.layout.mahjonggame_content_fragment,container,false);
        ButterKnife.inject(this,view);
        iMajhongGamePresenter = MajhongGamePresenter.getInstance(this);
        //System.out.println("onCreateView");
        return view;
    }

    @Override
    public RecyclerView getRecyvleView() {
        return recyclerView;
    }
    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                default:
                    iMajhongGamePresenter.updateMahjongGameInfo();
                    break;
            }
        }
    };
    @Override
    public Handler getHandler() {
        return handler;
    }

    @Override
    public Fragment getSelf() {
        return this;
    }

    @Override
    public void onStart() {
        super.onStart();
      //  System.out.println("start");
    }

    @Override
    public void onResume() {
        super.onResume();
        iMajhongGamePresenter.updateMahjongGameInfo();
       // System.out.println("resume");
    }

    @Override
    public void onPause() {
        super.onPause();
      //  System.out.println("pause");
    }

    @Override
    public void onStop() {
        super.onStop();
       // System.out.println("stop");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        iMajhongGamePresenter.endFragment();
       // System.out.println("destroy");
    }
    public static MahjongGameFragment newInstance(){
            return new MahjongGameFragment();
    }
}
